package net.wofly.sms;

import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class SmsUtil {
    
    static Logger logger = LoggerFactory.getLogger(SmsConfig.class);
    
    public static boolean sendMsg(String apiKey, String mobile, String msgText) {
        
        logger.info(">>>短信内容：" + msgText);
        
        //初始化clnt,使用单例方式
        //YunpianClient clnt = new YunpianClient("apikey").init();
        YunpianClient clnt = new YunpianClient(apiKey).init();
        
        //发送短信API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE, mobile);
        param.put(YunpianClient.TEXT, msgText);
        Result<SmsSingleSend> r = clnt.sms().single_send(param);
        //获取返回结果，返回码:r.getCode(),返回码描述:r.getMsg(),API结果:r.getData(),其他说明:r.getDetail(),调用异常:r.getThrowable()
        
        //账户:clnt.user().* 签名:clnt.sign().* 模版:clnt.tpl().* 短信:clnt.sms().* 语音:clnt.voice().* 流量:clnt.flow().*
        // 隐私通话:clnt.call
        // ().*
        
        //释放clnt
        clnt.close();
        return true;
    }
    
    
    public static void main(String[] args) {
        SmsUtil.sendMsg("", "","");
    }
}
